from django.contrib.auth.models import PermissionsMixin,  PermissionManager
from django.db import models
from rest_framework.permissions import BasePermission
import uuid
from django.contrib.contenttypes.models import ContentType
from apps.UserControl.models import BaseModel


class Permissions(BaseModel):
    name = models.CharField(verbose_name='name', max_length=255)
    types_choice = (
        ('目录', '目录'),
        ('菜单', '菜单'),
        ('接口', '接口')
    )
    types = models.CharField(choices=types_choice, default='接口', null=False, blank=False, max_length=32,
                             verbose_name='权限类型')
    parent = models.ForeignKey(to='self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='功能所属目录')
    objects = PermissionManager()
    sort = models.IntegerField('排序标记', default=1)
    method = models.CharField(null=False, blank=False, max_length=32, unique=True, verbose_name='目录名称/功能权限CODE')

    class Meta:
        verbose_name = '权限'
        verbose_name_plural = verbose_name
        db_table = 'control_Permissions'
        ordering = ('sort', )
